<template>
  <div>
     <el-dialog
      title="题目预览"
      :visible="showExamination"
      width="50%"
      @close="handleClose"
    >
      <!-- 第一大块 -->
      <template>
        <el-row>
          <el-col :span="6">
            <div class="grid-content bg-purple" >
              【题型】：{{list.questionType === "1"? '单选':"多选"}}
            </div>
          </el-col>
          <el-col :span="6"
            ><div class="grid-content bg-purple">
              【编号】：{{ list.id}}
            </div></el-col
          >
          <el-col :span="6"
            ><div class="grid-content bg-purple-light">
              【难度】：{{ difficultyDetail}}
            </div></el-col
          >
          <el-col :span="6"
            ><div class="grid-content bg-purple">
              【标签】：{{ list.tags }}
            </div></el-col
          >
          <el-col :span="6"
            ><div class="grid-content bg-purple-light">
              【学科】：{{ list.subject}}
            </div></el-col
          >
          <el-col :span="6"
            ><div class="grid-content bg-purple">
              【目录】：{{ list.catalog }}
            </div></el-col
          >
          <el-col :span="6"
            ><div class="grid-content bg-purple-light">
              【方向】：{{list.direction }}
            </div></el-col
          >
        </el-row>
      </template>
      <!-- 下划线
      <hr class="hr" />
     题干 -->
      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple-dark">
            【题干】：
            <span class="question">
              {{ filterHtmlTag(list.question) }}
            </span>
<!--
            <div class="questionStem">{{ list.questionStem }}</div>

            <el-checkbox
              v-for="item in list.options"
              :key="item.id"
              :checked="item.isRight === 1"
              disabled
              class="checkbox"
              >{{ item.title }}</el-checkbox
            > -->
          </div>
        </el-col>
      </el-row>
      <hr class="hr" />
      <!-- 参考答案 -->
      <el-row>
        <el-col :span="24"
          ><span class="grid-content bg-purple-dark">【参考答案】：</span>
          <el-button type="danger">
            <!-- //  -->
            <el-link :underline="false" :href="list.videoURL"
              >视频答案预览</el-link
            >
          </el-button>
        </el-col>
      </el-row>
      <hr class="hr" />
      <!-- 答案解析 -->
      <el-row>
        <el-col :span="24"
          ><span class="grid-content bg-purple-dark"
            >
            【答案解析】：{{ filterHtmlTag(list.answer) }}
            </span
          ></el-col
        >
      </el-row>
      <hr class="hr" />
      <!-- 题目备注 -->
      <el-row>
        <el-col :span="24"
          ><span class="grid-content bg-purple-dark"
            >
            【题目备注】：{{ list.catalog }}
            </span
          ></el-col
        >
      </el-row>
      <!-- 底部关闭按钮 -->
      <span slot="footer" class="dialog-footer">
        <el-row type="flex" justify="end" align="middle" style="height: 60px">
          <el-button @click="handleClose" type="primary">关闭</el-button>
        </el-row>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { difficulty } from '@/api/hmmm/constants.js' // 引入枚举文件---直接把这个对象引入了，可以直接使用，不需要在data里声明
export default {
  props: ['showExamination', 'list'],
  data () {
    return {
    }
  },
  created () {
  },
  methods: {
    // 点击关闭弹窗
    handleClose () {
      this.$emit('update:showExamination', false)
    },
    // 去除html标签
    filterHtmlTag (str = '') {
      let content = str.replace(/<\/?[^>]*>/g, '') // 去除标签
      content = content.replace(/[|]*\n/, '') // 去除行尾空格
      return content
    },

    // 根据枚举文件判断难度
    formatDifficulty (row) {
    //   console.log(row)
      const obj = difficulty.find(
        (item) => item.value === Number(row.difficulty)
      )
      // this.difficulty = obj?.label ? obj?.label : "未知";
      return obj?.label ? obj?.label : '未知'
    }
  },
  computed: {
    // 难度，根据枚举来显示
    difficultyDetail () {
      const obj = difficulty.find(
        (item) => item.value === Number(this.list.difficulty)
      )
      return obj?.label ? obj?.label : '未知'
    },
    // 题干提示，根据题型questionType来显示不同内容，利用计算属性
    questionStem () {
      if (this.list.questionType === 0) {
        return '多选题'
      } else if (this.list.questionType === 1) {
        return '单选题'
      } else {
        return ''
      }
    }
  }
}
</script>

<style>

</style>
